package jinyilw.swing.icon;

import jinyilw.swing.image.ImageTools;

import java.awt.Image;
import java.io.File;
import java.net.URL;

public class LazyCustomIcon extends LazyScaleIcon
{
	public LazyCustomIcon(Class<?> loadClass, String path, int width, int height)
	{
		super(loadClass, path);
		w = width;
		h = height;
	}

	public LazyCustomIcon(URL url, int width, int height)
	{
		super(url);
		w = width;
		h = height;
	}

	public LazyCustomIcon(File file, int width, int height)
	{
		super(file);
		w = width;
		h = height;
	}

	@Override
	public synchronized Image getImage()
	{
		if (image == null)
		{
			image = getOriginalImage();
			if (image == null)
				return null;
			int ww = (int) (w * systemScaleFactor);
			int hh = (int) (h * systemScaleFactor);
			image = ImageTools.getShapedImage(image, ww, hh);
		}
		return image;
	}
}
